package com.cbtx.module_sp.ui.fragment

import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import com.cbtx.module.base.ui.CommonFragment
import com.cbtx.module_sp.R
import com.just.agentweb.AgentWeb
import kotlinx.android.synthetic.main.sp_fragment_vr.*


class VrFragment: CommonFragment() {

    var mAgentWeb: AgentWeb? = null
    val url = "https://vr.txcb.com"
    override fun setLayout(): Any {
        return R.layout.sp_fragment_vr
    }

    override fun initView(view: View?, savedInstanceState: Bundle?) {

        initWeb()
    }


    fun initWeb(){
        mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(mWebFrameLayout, LinearLayout.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .createAgentWeb()
            .ready()
            .go(url)
    }

    override fun onPause() {
        super.onPause()
        mAgentWeb?.urlLoader?.loadUrl("")
    }

    override fun onResume() {
        super.onResume()

        mAgentWeb?.urlLoader?.loadUrl(url)
    }

    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)

         if (mIsLazyLoad){

             if (isVisibleToUser){
//                 mAgentWeb?.webLifeCycle?.onResume()
//                  initWeb()

                 mAgentWeb?.urlLoader?.loadUrl(url)

             }else{
                 mAgentWeb?.urlLoader?.loadUrl("")
             }
         }
    }



}